"""
@name : python常见性能分析工具
@author : wenyao
@projectname: sanchuanglianxi
"""
#golang  类c语言  预编译的
#python 自己提供了一些工具去分析代码的运行时间，运行内存

#自定义装饰器用法
# import time
# import re
# def time_wapper(func):
#     def _cost():
#         start = time.time()
#         for _ in range(10000):
#             result = func()
#         end = time.time()
#         cost = end - start
#         print("func cost:",cost)
#         return result
#     return _cost
#
# str1 = "test test1 test2 test3"
# #@time_wapper
# def fastest_replace():
#     return str1.replace(" ","-")
#
# #@time_wapper
# def slow_replace():
#     str2 = "-".join(str1.split(" "))
#     return str2
#
# #@time_wapper
# def sub_replace():
#     #patter = re.compile(r" ")
#     return  re.sub(r' ','-',str1)
#
# from timeit import Timer
# def time_analyze(func):
#     t1 = Timer("%s()"%func.__name__, "from __main__ import %s" % func.__name__)
#     print("%s : %s"%(func.__name__, t1.timeit(10000)))  #让函数执行10000次
#
# #print(sub_replace())
# if __name__ == "__main__":
#     time_analyze(fastest_replace)
#     time_analyze(slow_replace)
#     time_analyze(sub_replace)

#python timeit 模块
# if __name__ == "__mian__":
#     from timeit import Timer
#     t1 = Timer()

#常见的性能分析工具
#python  cprofiler  line_profiler  memory_profiler

#dis
import dis
def func1():
    tmp_lst = []
    lst = [1,2,3]
    for i in lst:
        tmp_lst.append(i*i)
    return tmp_lst

def func2():
    lst = [1,2,3]
    return [ i**i for i in lst]

dis.dis(func1)
dis.dis(func2)

#作业
## 面向对象 回合制游戏的作业
#上下文管理器
#20道题
#爬虫

#linux 几种io模型
